<?#//v.3.1.2
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////

include "../includes/config.inc.php";
include "loggedin.inc.php";


if($_POST['action'] == "newsletter" && phpa_securepost($_POST)) {
	#//
	if(empty($_POST['subject']) || empty($_POST['content'])) {
		$ERR = $ERR_5014;
	} else {
		$COUNTER = 0;
		switch($_POST['usersfilter']) {
			case 'all':
			$query = "select email from PHPAUCTIONXL_users where nletter='1'";
			break;
			case 'active':
			$query = "select email from PHPAUCTIONXL_users where nletter='1' AND suspended=0";
			break;
			case 'admin':
			$query = "select email from PHPAUCTIONXL_users where nletter='1' AND suspended=1";
			break;
			case 'fee':
			$query = "select email from PHPAUCTIONXL_users where nletter='1' AND suspended=9";
			break;
			case 'confirmed':
			$query = "select email from PHPAUCTIONXL_users where nletter='1' AND suspended=8";
			break;
		}
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)) {
			if(mail($row['email'],stripslashes($_POST['subject']),stripslashes($_POST['content']),"From:".$SETTINGS['sitename']." <".$SETTINGS['adminmail'].">\n"."Content-Type: text/html; charset=$CHARSET")) {
				$COUNTER++;
			}
		}
		if(!$result) {
			$ERR = $ERR_001;
		} else {
			$ERR = $COUNTER.$MSG_5300;
		}
	}
}


?><HEAD>
<link rel='stylesheet' type='text/css' href='style.css' />
<TITLE>Newsletter Admin</TITLE>
<script type="text/javascript" src="../js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	language: "en",
	plugins : "table",
	theme_advanced_buttons1 : "backcolor, forecolor, bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
	theme_advanced_buttons2 : "fontselect, fontsizeselect",
	theme_advanced_buttons3 : "tablecontrols",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	force_br_newlines : "false",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
});
</script>
<link href="css/main.css" rel="stylesheet" type="text/css">
</HEAD>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="titulo">
        <tr>
        <td class="icono"><img src="images/pref_icon2.gif" width="28" height="28"></td>
          <td class="breadcrumbs"><p><span><?=$MSG_25_0008?></span>&nbsp;&gt;&gt;&nbsp; <?=$MSG_607?></p></td>
        </tr>
     </table>
	 </td>
  </tr>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="middle">
		<FORM NAME=newsletter ACTION="<? print basename($_SERVER['PHP_SELF']); ?>" METHOD="POST">
          <TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0"  class="base" ALIGN="CENTER" style="border:1px solid #ccc;">
            <TR>
              <TD ALIGN=CENTER class=title><p><? print $MSG_607; ?></p></TD>
            </TR>
            <TR>
              <TD>
			  <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" cellspacing="0" BGCOLOR="#FFFFFF">
                  <?
                  if(!empty($ERR)) {
				  ?>
                  <TR>
                    <TD COLSPAN=2 ><p><? print $ERR; ?></p> </TD>
                  </TR>
                  <?
                  }
				  ?>
                  <TR>
                    <TD WIDTH="125" VALIGN="top" class="gris"  ><p class="blue"><? print "$MSG_5299 *"; ?> </p></TD>
                    <TD WIDTH="486" class="gris"><p><SELECT NAME=usersfilter onChange="SubmitFilter()">
                        <OPTION VALUE=all><?=$MSG_5296?></OPTION>
                        <OPTION VALUE=active><?=$MSG_5291?></OPTION>
                        <OPTION VALUE=admin ><?=$MSG_5294?></OPTION>
                        <OPTION VALUE=fee><?=$MSG_5293?></OPTION>
                        <OPTION VALUE=confirmed ><?=$MSG_5292?></OPTION>
                      </SELECT></p>
                    </TD>
                  </TR>
                  <TR>
                    <TD WIDTH="125" VALIGN="top" > <p class="blue"><? print "$MSG_606 *"; ?> </p></TD>
                    <TD WIDTH="486"><p><INPUT TYPE=text NAME=subject SIZE=40 MAXLENGTH=255 VALUE="<? print $subject; ?>"></p>
                    </TD>
                  </TR>
                  <TR>
                    <TD WIDTH="125" VALIGN="top" > <p class="blue"><? print "$MSG_605 *"; ?> </p></TD>
                    <TD WIDTH="486"><p><?=$MSG_30_0055?></p><BR><p><TEXTAREA NAME=content COLS=85 ROWS=20><? print $content; ?></TEXTAREA></p>
                    </TD>
                  </TR>
                  <TR>
                    <TD WIDTH="125" VALIGN="top"></TD>
                    <TD WIDTH="486"><p><INPUT TYPE=submit VALUE="<?=$MSG_25_0015?>" class="action">
					
					</p>
                      <INPUT TYPE="hidden" NAME="action" VALUE="newsletter">
					  <INPUT TYPE="hidden" NAME="security" VALUE="<?php echo $_SESSION['security'];?>" />
                    </TD>
                  </TR>
                </TABLE>
				
			  </TD>
            </TR>
          </TABLE>
        </FORM>
      </TD>
  </TR>
</TABLE>
</BODY>
</HTML>
